package com.lzy.dao.key;

import java.util.List;

import org.hibernate.classic.Session;
import org.springframework.stereotype.Component;

import com.lzy.dao.HibernateDao;
import com.lzy.entity.IMFolder;

@Component
public class IMFolderDaoImpl extends HibernateDao implements IMFolderDao{
	
	public List<IMFolder> queryList() {
		
		Session session = sessionFactory.getCurrentSession();
		
		List<IMFolder> folders = session.createQuery("from IMFolder").list();
		
		return folders;
	}
	
	public IMFolder queryById(int id) {
		
		Session session = sessionFactory.getCurrentSession();
		
		IMFolder folder = (IMFolder)session.createQuery("from IMFolder where typeID=?").setInteger(0, id).uniqueResult();
		
		return folder;
	}
	
	public List<IMFolder> queryByParentId(int id) {
		
		Session session = sessionFactory.getCurrentSession();
		
		List<IMFolder> folders = session.createQuery("from IMFolder where parentId=?").setInteger(0, id).list();
		
		return folders;
	}
	
	public void add(IMFolder folder) {
		Session session = sessionFactory.getCurrentSession();
		session.save(folder);
	}
	
	public void del(int id) {
		Session session = sessionFactory.getCurrentSession();
		Object folder = session.load(IMFolder.class, id);
		session.delete(folder);
	}
	
	public void del(IMFolder folder) {
		Session session = sessionFactory.getCurrentSession();
		session.delete(folder);
	}
	
	public IMFolder query(int id) {
		// TODO Auto-generated method stub
		Session session = sessionFactory.getCurrentSession();
		IMFolder folder = (IMFolder)session.load(IMFolder.class, id);
		return folder;
	}
	
	public void update(IMFolder folder) {
		Session session = sessionFactory.getCurrentSession();
		session.update(folder);
	}
	
}
